package com.cls.mc_demo.common.intf;

import com.cls.mc_demo.common.Const;
import com.cls.mc_demo.common.SPPacket;
import jakarta.annotation.PostConstruct;
import org.tio.core.ChannelContext;


/**
 * @author CLS
 * @since 2023/08/04
 */
public abstract class CustomCommonBsHandler implements CustomCommonBsHandlerIntf {
    protected static CustomCommonBsHandler absCommonBsHandler;

    /**
     * 初始化
     */
    @PostConstruct
    public void init() {
        absCommonBsHandler = this;
    }

    @Override
    public void handler(SPPacket packet, ChannelContext channelContext) throws Exception {
        String jsonStr = null;
        if (packet.getBody() != null) {
            // 字节数组转字符串
            jsonStr = new String(packet.getBody(), Const.CHARSET);
        }

        handler(packet, jsonStr, channelContext);
    }

    public abstract void handler(SPPacket packet, String bsBody, ChannelContext channelContext) throws Exception;

}
